package com.jeesite.modules.pt.web;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.pt.entity.PtSetting;
import com.jeesite.modules.pt.service.PtSettingService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.pt.entity.PtXinshou;
import com.jeesite.modules.pt.service.PtXinshouService;

/**
 * 新手任务Controller
 * @author 李寒冰
 * @version 2025-07-09
 */
@Controller
@RequestMapping(value = "${adminPath}/pt/ptXinshou")
public class PtXinshouController extends BaseController {

	@Autowired
	private PtXinshouService ptXinshouService;
    @Autowired
    private PtSettingService ptSettingService;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public PtXinshou get(String id, boolean isNewRecord) {
		return ptXinshouService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("pt:ptXinshou:view")
	@RequestMapping(value = {"list", ""})
	public String list(PtXinshou ptXinshou, Model model) {
		String xinshou_open = ptSettingService.getValueByKey("xinshou_open");
		String xinshou_time = ptSettingService.getValueByKey("xinshou_time");
		String xinshou_jine = ptSettingService.getValueByKey("xinshou_jine");
		String xinshou_parent_jine = ptSettingService.getValueByKey("xinshou_parent_jine");
		model.addAttribute("xinshou_open", xinshou_open);
		model.addAttribute("xinshou_time", xinshou_time);
		model.addAttribute("xinshou_jine", xinshou_jine);
		model.addAttribute("xinshou_parent_jine", xinshou_parent_jine);
		model.addAttribute("ptXinshou", ptXinshou);
		return "modules/pt/ptXinshouList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("pt:ptXinshou:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<PtXinshou> listData(PtXinshou ptXinshou, HttpServletRequest request, HttpServletResponse response) {
		ptXinshou.setPage(new Page<>(request, response));
		Page<PtXinshou> page = ptXinshouService.findPage(ptXinshou);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("pt:ptXinshou:view")
	@RequestMapping(value = "form")
	public String form(PtXinshou ptXinshou, Model model) {
		model.addAttribute("ptXinshou", ptXinshou);
		return "modules/pt/ptXinshouForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("pt:ptXinshou:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated PtXinshou ptXinshou) {
		ptXinshouService.save(ptXinshou);
		return renderResult(Global.TRUE, text("保存新手任务成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("pt:ptXinshou:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(PtXinshou ptXinshou) {
		ptXinshouService.delete(ptXinshou);
		return renderResult(Global.TRUE, text("删除新手任务成功！"));
	}
	
}